<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>15_过滤器</title>
</head>
<body>
    <div id="demo">
        <h1>显示各种格式的时间</h1>
        <p>{{time}}</p>
        <p>年月日:{{time | dateFormat}}</p>
        <p>小时分:{{time | dateFormat('HH:mm:ss')}}</p>
    </div>
</body>
<script type="text/javascript" src="../vue.js"></script>
<script src="https://cdn.bootcss.com/moment.js/2.24.0/moment.min.js"></script>
<script>
    //定义过滤器
    Vue.filter('dateFormat',function (value,format="YYYY-MM-DD HH:mm:ss") {
        return moment(value).format(format);
    });

    const vm = new Vue({
        el:'#demo',
        data:{
            time:new Date()
        },
        mounted() {
            setInterval(()=>{
                this.time = new Date()
            },1000)
        }
    });
</script>
</html>